﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
namespace DAL
{
    public class huiyuanDAL
    {
        DBHelper db = new DBHelper();
        // --姓名
        //   --邮箱
        //   --性别
        //      --加入时间
        //--开卡数量
        //--开通天数
        //   --会员积分
        public int hyadd(string name, string mail, string sex, string leave, int carnum, int cartime, int carintegral,int random) //会员添加
        {
            string sql = string.Format("INSERT INTO [dbo].[huiyuan]([uname],[mail],[sex],[leave],[carnum],[cartime],[carintegral],[Mstatus],randomcnum)VALUES('{0}','{1}', '{2}','{3}','{4}','{5}','{6}','{7}','{8}')", name, mail, sex, leave, carnum, cartime, carintegral, 1, random);
            int a = db.zsg(sql);
            return a;
        }

        public DataTable hydgvshow()  //显示dgv数据
        {
            string sql = string.Format("select * from huiyuan where Mstatus=1");
            return db.cx(sql);
        }
        public DataTable hydgvshow1()  //显示dgv1数据
        {
            string sql = string.Format("select * from huiyuan ");
            return db.cx(sql);
        }
        public DataTable view() //显示主视图用户
        {
            string sql = string.Format("select * from huiyuan where uname is not null");
            return db.cx(sql) ;
        }
        public DataTable viewcarnum() //显示主视图销售卡量
        {
            string sql = string.Format("select sum(carnum) as xx  from huiyuan");
            return db.cx(sql);
        }

        public DataTable MmodifyShow(int id)    //用户的修改赋值去主页面
        {
            string sql = string.Format("select * from huiyuan where id='{0}'",id);
            return db.cx(sql);
        }

        public int mModifyupdata(string name,string mail,string sex,string leave, int carnum,int cartime,int id) //用户的修改
        {
            string sql = string.Format("UPDATE [dbo].[huiyuan]SET [uname] = '{0}',[mail] ='{1}',[sex] = '{2}',[leave] ='{3}',[carnum] = '{4}',[cartime] = '{5}'  WHERE id='{6}'", name, mail, sex, leave, carnum, cartime,id);
            return db.zsg(sql);
        }
        public int mModifyDel(int id)    // 删除用户
        {
            String sql = string.Format("update huiyuan set Mstatus ='{0}' where id='{1}' ",0,id);
            return db.zsg(sql);
        }

        public DataTable mReach1(string name,int jyallmember, int leave )// 查询用户 状态是1的所有用户 ,禁用用户
        {
            string sql = string.Format("select * from huiyuan where 1>0 and Mstatus=1");
            if (!string.IsNullOrEmpty(name))
            {
                sql += string.Format("and  uname like '%{0}%' ", name);
            }
            if (jyallmember>0)
            {
                sql += string.Format("or  Mstatus = '0' ", name);
            }
            if (leave==2)
            {
                sql += string.Format("and  leave = '已请假' ");
            }
            return db.cx(sql);
        }
        public DataTable yhrandom(int name ,int pwd)   //判断是不是用户
        {
            string sql = string.Format("SELECT * FROM  zhanghao WHERE   zh='{0}' and   mm='{1}' and isr =0",name,pwd);
            return db.cx(sql);
        } 

        public DataTable yzrandom(int random)   //验证随机码正确错误
        {
            string sql=   string.Format("select * from huiyuan where randomcnum ='{0}'",random);
            return db.cx(sql);
        }
    }
}
